<!DOCTYPE html>
<html lang="en"><!-- InstanceBegin template="/Templates/MainTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
<!-- #BeginEditable "doctitle" -->
<title>how to enhance Jdon framework to DCI framework ?</title>  
<!-- #EndEditable -->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
    <!-- Bootstrap core CSS -->
     <link rel="stylesheet" href="css/bootstrap.min.css">   

    <!-- Custom styles for this template -->
    <link href="css/starter-template.css" rel="stylesheet">

   <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->    
  </head>
<body>
 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html">Jdon Framework</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
                <li class="active"><a href="index.html">Home</a></li>
               <li><a href="https://sourceforge.net/projects/jdon/files/">Download</a></li>
               <li><a href="doc.htm" >Document</a></li>
               <li><a href="quickconf.html">Qucik Start</a> </li>
               <li><a href="examples.html">Examples</a></li>
               <li ><a href="https://github.com/banq/jdonframework">Github</a></li>
               <li><a href="articles.html">Articles</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    

    <div class="container">
     <div class="starter-template">     
    
 <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">  
  <tr>     
    <td bgcolor="#FFFFFF"  valign="top" align="left">

                  
				<!-- #BeginEditable "main" -->
				<h3>how to enhance Jdon framework to DCI framework ? <br>
				  </h3>
                <p>In Jdon framework 6.4 case , I use Domain Events implements a DCI:<br>
                </p>
                <p>Data Model of DCI:<br>
                </p>
                <table width="100%"  border="0" cellpadding="1" cellspacing="0" bgcolor="#CCCCCC">
                  <tr>
                    <td><P>&nbsp;</P>
                      <p>@Model<br>
                        public class User Model {<br>
                        &nbsp;&nbsp;private String userId;<br>
                        &nbsp;&nbsp;private String name;<br>
                        <br>
                        &nbsp;&nbsp;@Inject<br>
                        &nbsp;&nbsp;private ComputerRole computerRole;<br>
                        }</p></td>
                  </tr>
                </table>
                <p><br>
                  <br>
                  Role : domain events is Role's interactions of DCI<br>
  &nbsp;&nbsp;</p>
                <table width="100%"  border="0" cellpadding="1" cellspacing="0" bgcolor="#CCCCCC">
                  <tr bgcolor="#CCCCCC">
                    <td><P>&nbsp;</P>
                      <p>@Introduce(&quot;message&quot;)<br>
                        public class ComputerRole {<br>
                      </p>
                      <p> &nbsp;&nbsp;@Send(&quot;computeCount&quot;)<br>
                        &nbsp;&nbsp;public DomainMessage computeCount(UserModel user) {<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;return new DomainMessage(user);<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;}<br>
                      </p>
                      <p> &nbsp;&nbsp;&nbsp;@Send(&quot;saveUser&quot;)<br>
                        &nbsp;&nbsp;public DomainMessage save(UserModel user) {<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new DomainMessage(user);<br>
                        &nbsp;&nbsp;}<br>
                      </p>
                      <p>} <br>
                      </p></td>
                  </tr>
                </table>
                <p>&nbsp;</p>
                <p>Context of DCI: Role will be injected into data model:<br>
                </p>
                <table width="100%"  border="0" cellpadding="1" cellspacing="0" bgcolor="#CCCCCC">
                  <tr bgcolor="#CCCCCC">
                    <td><P>&nbsp;</P>
                      <p>public class ComputeContext {<br>
                      </p>
                      <p> &nbsp;&nbsp;private DomainMessage ageAsyncResult;<br>
                      </p>
                      <p> &nbsp;&nbsp;public void preloadData(UserModel user) {<br>
                        &nbsp;&nbsp;if (ageAsyncResult == null)<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;ageAsyncResult = user.getUserDomainEvents().computeCount(user);<br>
                        &nbsp;&nbsp;}<br>
                      </p>
                      <p> &nbsp;&nbsp;public int loadCountNow(UserModel user) {<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;preloadData(user);<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;return (Integer) ageAsyncResult.getEventResult();<br>
                        &nbsp;&nbsp;}<br>
                      </p>
                      <p> &nbsp;&nbsp;public int loadCountByAsync(UserModel user) {<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;if (ageAsyncResult == null)<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ageAsyncResult = user.getUserDomainEvents().computeCount(user);<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;else if (ageAsyncResult != null)<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (Integer) ageAsyncResult.getEventResult();<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;return -1;<br>
                        &nbsp;&nbsp; }<br>
                        }</p>
                      <p></p></td>
                  </tr>
                </table>
                <p>&nbsp;</p>
                <p>Domain Events and DCI are  different perspective for one thing,  DCI is from the UML(such as four-colors UML) map directly over the prototype , and therefore allows developers to deal directly with DCI that can reduce unnecessary translation of distortion.</p>
                <p>So my idea is:  Domain Events is as the underlying mechanism of DCI, from lower level to high: Dirsruptor ---&gt; Domain Events ---&gt; DCI, DCI is the highest level.<br>
                </p>
                <p>How about DCI and MVC? or DCI and Service of SOA? how to integrate them?<br>
                </p>
                <p>the Article :DCI patterns - how to write DCI context in Ruby  have a problem: The most important part, however is the way the context class is written.  Should the application object (a model) know about the contexts?<br>
                  They say there  are some options:</p>
                <p>1. the application object has access to all the possible contexts. The controller just calls methods like: application.register_new_user(..) and it's the application that initializes the context.</p>
                <p>2. controller has the knowledge about the specific &quot;global&quot; context it handles: NewUserContext.new(..).execute</p>
                <p>3. controllers as we know them (Rails) disappear, the wiring between actions and context takes place in a configuration file.<br>
                </p>
                <p>I think REST + DCI is naturally pattern.<br>
                </p>
                <p>REST verb has four verb: post get post delete, these verbs fire events, the events consumer is the Restful resource, such as post a product, the &quot;post&quot; event  will active url &quot;/product&quot;.  and in the class of &quot;/product &quot; will have a context that accept the &quot;post&quot; event. the context should be the context of DCI.<br>
                </p>
                <p>so in REST +DCI there is no MVC, MVC pattern is a structural pattern and not for events behavior pattern, but REST althought is for resource, but resource need operation events.</p>
                <p>About REST's four verb 'post / put / get / delet' , the  server can  response to them in a resource manager context, the resource is  same as  data model of DCI, here is a post resource context:<br>
                </p>
                <table width="100%"  border="0" cellpadding="1" cellspacing="0" bgcolor="#CCCCCC">
                  <tr bgcolor="#CCCCCC">
                    <td><P>&nbsp;</P>
                      <p>@Path(&quot;/users&quot;)<br>
                        @POST<br>
                        public Represent post(UserModel user) {<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;if (validate(user))<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new Html(&quot;/newUser.jsp&quot;, &quot;user&quot;, user);<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;user.setUserId(Integer.toString(user.hashCode()));<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;//assign DCI role to data model<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;RepositoryManagerIF rm = (RepositoryManagerIF) roleAssigner.assign(user, new RepositoryManagerEventImp());<br>
                        &nbsp;&nbsp;&nbsp;&nbsp;//this method will send domain events to repository   rm.remember(user);</p>
                      <p> &nbsp;&nbsp;&nbsp;&nbsp;return new State(&quot;/&quot;);<br>
                        }<br>
                      </p>
                      <p></p></td>
                  </tr>
                </table>
                <p>&nbsp;</p>
                <p>Robot source：<a href="https://github.com/banq/jdonframework/tree/master/example/robot" target="_blank">GitHUB</a></p>
                <p>REST + DCI + Domain Events example Robot download: <a href="http://sourceforge.net/projects/jdon/files/JdonFramework-App/samples-6.5/">here</a> robot.rar is CQRS architecture.<br>
                </p>
                <p></p>
                <p><a href="match.html">DDD CQRS EventSourcing example source: football Match</a></p>
                <p><a href="ces.html"><strong>CES:Context Event and State</strong></a></p>
                <p><a href="https://github.com/banq/jdonframework/tree/master/example">JdonFramework DDD + CQRS + EventSourcing examples </a></p>
                <p></p> 
                  <p>　　</p>
                  <p>&nbsp;</p>
                  <!-- #EndEditable -->
                 
			  	
          </td>
		  <td width="340" valign="top"  bgcolor="#FFFFD7"> 
          <div class="adsensf" id="vgad336x280">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>         
 </td>
  </tr>
</table>


<table width="100%" border="0" cellspacing="0" cellpadding="0" height="2" bgcolor="#000000"  align="center">
              <tr>
                <td></td>
              </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td height="20" bgcolor="#CAC9BB" align="center">
  
  </td>
</tr>
</table>
 </div>
</div><!-- /.container -->

<!-- InstanceBeginEditable name="EditRegion3" --><!-- InstanceEndEditable -->
        <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
<!-- AddThis Smart Layers BEGIN -->
<!-- Go to http://www.addthis.com/get/smart-layers to customize -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52c4b79515624135"></script>
<script type="text/javascript">
  addthis.layers({
    'theme' : 'transparent',
    'share' : {
      'position' : 'left',
      'numPreferredServices' : 5
    },  
    'whatsnext' : {},  
    'recommended' : {} 
  });
</script>
<!-- AddThis Smart Layers END -->    
</body>
<!-- InstanceEnd --></html>
